//
//  MasterCell.m
//  WanCaiC8
//
//  Created by tangang on 2018/3/12.
//  Copyright © 2018年 tangang. All rights reserved.
//

#import "MasterCell.h"

@implementation MasterCell{
    UIImageView     *imageRank;
    UIImageView     *headImage;
    QXLable         *labRank;
    QXLable         *labName;
    UIButton         *btneExceptional;
}

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    if (self=[super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        WS(weakSelf);
        imageRank=[[UIImageView alloc]initWithImage:[UIImage imageNamed:@"ranking_1"]];
        [self.contentView addSubview:imageRank];
        [imageRank mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerY.equalTo(weakSelf.contentView);
            make.left.equalTo(weakSelf.contentView).with.offset(defaultLeftMargin);
            make.size.mas_equalTo(CGSizeMake(19, 27));
        }];
        
        labRank =[[QXLable alloc]init];
        labRank.textAlignment=NSTextAlignmentCenter;
        [self.contentView addSubview:labRank];
        [labRank mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerY.equalTo(weakSelf.contentView);
            make.centerX.equalTo(imageRank);
            make.size.mas_equalTo(CGSizeMake(30, 20));
        }];
        
        headImage=[[UIImageView alloc]initWithImage:[UIImage imageNamed:@"avatar"]];
        headImage.layer.masksToBounds=YES;
        headImage.layer.cornerRadius=real_size(20);
        [self.contentView addSubview:headImage];
        [headImage mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(labRank.mas_right).with.offset(defaultLeftMargin);
            make.top.equalTo(self.contentView).with.offset(defaultLeftMargin);
            make.bottom.equalTo(self.contentView).with.offset(-defaultLeftMargin);
            make.size.mas_equalTo(CGSizeMake(defaultHeadSize,defaultHeadSize));
        }];
        
        labName=[[QXLable alloc]init];
        labName.text=@"茶之轨迹";
        [self.contentView addSubview:labName];
        [labName mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(headImage.mas_right).with.offset(defaultLeftMargin);
            make.centerY.equalTo(self.contentView);
        }];
        
        btneExceptional =[[UIButton alloc]init];
        btneExceptional.userInteractionEnabled=NO;
        [btneExceptional setImage:[UIImage imageNamed:@"master_integral"] forState:UIControlStateNormal];
        [btneExceptional setTitleColor:DEFAULTORANGECOLOR forState:UIControlStateNormal];
        btneExceptional.contentHorizontalAlignment=
        UIControlContentHorizontalAlignmentRight;
        [btneExceptional.titleLabel setFont:[UIFont systemFontOfSize:13]];
        [self.contentView addSubview:btneExceptional];
        [btneExceptional mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerY.equalTo(headImage);
            make.right.equalTo(weakSelf.contentView).with.offset(-defaultLeftMargin);
            make.size.mas_equalTo(CGSizeMake(200, 30));
        }];
        
        UIView *line=[[UIView alloc]init];
        line.backgroundColor=DEFAULTBGCOLOR;
        [self.contentView addSubview:line];
        [line mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.right.top.equalTo(self.contentView);
            make.height.mas_equalTo(defaultLineHeight);
        }];
    }
    return self;
}

- (void)setModel:(RankingUserModel *)model{
    _model=model;
    if (model.Rank<=3) {
        labRank.text=@"";
        imageRank.image=[UIImage imageNamed:[NSString stringWithFormat:@"ranking_%ld",model.Rank]];
        labName.textColor=DEFAULTORANGECOLOR;
    }else{
        imageRank.image=nil;
        labRank.text=[NSString stringWithFormat:@"%ld",model.Rank];
        labName.textColor=DEFAULTTEXTBLACKCOLOR;
    }
    [headImage sd_setImageWithURL:[NSURL URLWithString:model.Avater] placeholderImage:[UIImage imageNamed:@"avatar"]];
    labName.text=model.NickName;
    [btneExceptional setTitle:[NSString stringWithFormat:@" %ld",model.Number] forState:UIControlStateNormal];
    
}

- (void)setType:(RankType)type{
    if (type==RankTypeFans) {
        [btneExceptional setImage:[UIImage imageNamed:@"fans"] forState:UIControlStateNormal];
    }
}

@end
